<template>
  <view class="container">
    <template v-if="status == 1">
      <Parents :secondindex="secondindex" @goxuebapage="recivetabbar"></Parents>
      <TabBar :parentlist="tabbarlist1" @changetabbar="recivetabbarindex" :tabbarindex="currenttabber"></TabBar>
    </template>
    <template v-if="status == 2">
      <Teacher :secondindex="secondindex"></Teacher>
      <TabBar :parentlist="tabbarlist2" @changetabbar="recivetabbarindex" :tabbarindex="currenttabber"></TabBar>
    </template>
  </view>
</template>

<script>
import TabBar from '@/components/tabbar/tabbar.vue';
import Parents from '@/components/parents/parents.vue';
import Teacher from '@/components/teacher/teacher.vue';

import store from '@/store/index.js';

export default {
  components: {
    TabBar,
    Parents,
    Teacher
  },
  data() {
    return {
      // status 家长端= 1   教师端=2
      status: 1,
      secondindex: 0, // 控制显示tabbar的页面
      currenttabber: null, // 子组件中页面跳转，传递的tabbar的索引
      tabbarlist1: [
        {
          iconPath: '/static/tabbarimg/index.png',
          selectedIconPath: '/static/tabbarimg/indexact.png',
          text: '首页'
        },
        {
          iconPath: '/static/tabbarimg/xuebatohome.png',
          selectedIconPath: '/static/tabbarimg/xuebadaojiaact.png',
          text: '考神临门'
        },
        {
          iconPath: '/static/tabbarimg/book.png',
          selectedIconPath: '/static/tabbarimg/bookact.png',
          text: '资料库'
        },
        {
          iconPath: '/static/tabbarimg/my.png',
          selectedIconPath: '/static/tabbarimg/myact.png',
          text: '我的'
        }
      ],
      tabbarlist2: [
        {
          iconPath: '/static/tabbarimg/index.png',
          selectedIconPath: '/static/tabbarimg/indexact.png',
          text: '首页'
        },

        {
          iconPath: '/static/tabbarimg/book.png',
          selectedIconPath: '/static/tabbarimg/bookact.png',
          text: '资料库'
        },
        {
          iconPath: '/static/tabbarimg/my.png',
          selectedIconPath: '/static/tabbarimg/myact.png',
          text: '我的'
        }
      ]
    };
  },
  methods: {
    // 获取用户信息
    async getuserinfo() {
      const res = await uni.$http.post('/user/profile');
      console.log('用户信息', res.data.data);

      uni.setStorageSync('rzstatus', res.data.data.position_status);
      // uni.setStorageSync('userinfo2', JSON.stringify(res.data.data));
      this.$store.state.userinfo = res.data.data;
      // console.log('index的用户信息', this.$store.state.userinfo);
    },
    // 接受tabbar传递的索引
    recivetabbarindex(e) {
      console.log(e);
      this.secondindex = e;
      this.currenttabber = e;
    },
    // 接受家长端的tabbarindex
    recivetabbar(value) {
      console.log('recivetabbar-->', value);
      this.secondindex = value;
      this.currenttabber = value;
    }
  },
  onLoad(e) {
    if (e.user_id) {
      console.log('用户id', e.user_id);
    }
    if (e.status) {
      // 在此处加判断上一个页面是从哪进来的
      this.status = e.status;
      if (e.tabbarindex) {
        this.secondindex = e.tabbarindex;
        this.currenttabber = e.tabbarindex;
      } else {
        this.currenttabber = 0;
        this.secondindex = 0;
      }
    }
  },
  onShow() {
    // 获取用户信息
    if (uni.getStorageSync('token')) {
      this.getuserinfo();
    }
  },
  onHide() {
    console.log('子组件', this.$children);
  }
};
</script>

<style>
.uni-popup {
  z-index: 1002 !important;
}
.container {
  box-sizing: border-box;
}
</style>
